/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Search;

/**
 *
 * @author Nuf
 */
public class ElementRelevance implements Comparable<ElementRelevance> {
    private String document;
    private String element;
    private String type;
    private float tf;
    private float idf;
    private int relevant;
    private int wordFoundCouner;

    public ElementRelevance(String document, String element, String type){
        this.document = document;
        this.element = element;
        this.tf = 0;
        this.idf = 0;
        this.wordFoundCouner = 0;
        this.type = type;
    }

    public void addOneWordStats(float tf, float idf){
       this.tf+=tf;
       this.idf+=idf;
       this.wordFoundCouner++;
    }

    public String getDocument(){
        return document;
    }

    public String getElement(){
        return element;
    }

    public int isRevelant(){
        return relevant;
    }

    public float getTf() {
        return tf;
    }

    public float getIdf() {
        return idf;
    }

    public String getType() {
        return type;
    }



    @Override
    public int compareTo(ElementRelevance o) {
//        float toCompare = o.getIdf() - this.getIdf();
        float toCompare = (o.getIdf()*o.getTf()) - (this.getIdf()*this.getTf());
        if(toCompare == 0)
            return 0;
        else if(toCompare > 0)
            return 1;
        else
            return -1;
    }

    public String toString(){
        return ((this.getIdf() * this.getTf()) + " - " + this.getDocument() + " " + this.getElement());
    }

}
